package com.aaa.mrcai.service.impl;

import com.aaa.mrcai.mapper.ShopMapper;
import com.aaa.mrcai.pojo.entity.Shop;
import com.aaa.mrcai.pojo.entity.UserInfo;
import com.aaa.mrcai.result.AjaxResult;
import com.aaa.mrcai.service.ShopService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import javax.servlet.ServletContext;
import java.util.List;

/**
 * @Author:Li-Yan-Chun
 * @Date:2021/12/19 20:18
 */
@Service
public class ShopServiceImpl implements ShopService {
    @Autowired
    private ShopMapper shopMapper;
    @Autowired
    private ServletContext servletContext;

    @Override
    public AjaxResult list(int uid) {

        List<Shop> list = shopMapper.list(uid);
        return AjaxResult.success(list);
    }

    @Override
    public AjaxResult getUid() {
        UserInfo user = (UserInfo) servletContext.getAttribute("user");
        Integer uid = user.getUserLogin().getUid();
        System.out.println(uid);
        return AjaxResult.success(uid);
    }

    @Override
    public AjaxResult deleteGoods(int id) {
        int i = shopMapper.deleteGoods(id);
        if (i>0){
            return AjaxResult.success();
        }
        return AjaxResult.defeated();
    }
}
